Comparing the Optimization Methods#

[1]:
# import libraries
import jax.numpy as jnp
from optymus.benchmark import methods_comparison
[2]:
from optymus.benchmark import HimmeblauFunction

# define the objective function
f = HimmeblauFunction()

# define the initial point
initial_point = jnp.array([0, 5])

f.plot()
../../_images/examples_notebooks_4.methods_comparison_2_0.png
[3]:
comparison = methods_comparison(f, initial_point, verbose=False, max_iter=100)
100%|██████████| 11/11 [02:11<00:00, 11.98s/it]
[4]:
comparison['results']
[4]:
method x_opt f_min n_iter time
0 Gradient Descent [-2.8051180808608414, 3.131312517644538] 1.2151348386129352e-15 5 0.197249
1 Univariant [-2.8051180976907424, 3.1313125184240542] 3.74326772617301e-15 3 0.259626
2 BFGS [-2.8051181454077057, 3.131313798010024] 6.588583976279607e-11 4 0.277029
3 Conjugate Gradients (fletcher_reeves) [-2.8051180908358573, 3.1313124657578117] 1.1158273896131452e-13 3 0.311757
4 Powell [-2.8051181469023305, 3.131312584887037] 2.9009608415117576e-13 2 0.554102
5 Newton-Raphson [2.999999999996896, 2.0000000000133182] 2.545076537982263e-21 5 1.122987
6 Adagrad [-1.9076663457910115, 3.6954353270806095] 35.98393817255608 100 2.003074
7 Adamax [-2.822263741759333, 3.1272400512420284] 0.010357710402059517 100 2.009426
8 RMSprop [-0.09997346539296385, -0.09990007036924864] 173.25400825979125 100 2.020720
9 Yogi [-1.0154588800168631, 4.1608946545268575] 120.17736216526826 100 2.102989
10 Adam [-2.793052990299834, 3.140203199556635] 0.008040011808338025 100 2.206574
[5]:
from optymus.plots import plot_optim

plot_optim(f_obj=f, x0=initial_point, comparison=comparison, show=True, notebook=True,)

Data type cannot be displayed: application/vnd.plotly.v1+json

McCormick Function#

[6]:
from optymus.benchmark import MccormickFunction

# define the objective function
f = MccormickFunction()

# define the initial point
initial_point = jnp.array([2, 2])

f.plot()
../../_images/examples_notebooks_4.methods_comparison_7_0.png
[7]:
comparison = methods_comparison(f, initial_point, verbose=False, max_iter=100, learning_rate=0.01)
100%|██████████| 11/11 [02:24<00:00, 13.12s/it]
[8]:
comparison['results']
[8]:
method x_opt f_min n_iter time
0 Gradient Descent [2.5943825933594176, 1.5944038260303497] 1.2283696990657877 4 0.233018
1 BFGS [2.5943948334728786, 1.5943947965070397] 1.2283696986089008 3 0.246913
2 Conjugate Gradients (fletcher_reeves) [2.59439519159073, 1.5943950366170843] 1.2283696986087804 3 0.325162
3 Newton-Raphson [2.594395110694578, 1.5943950969522729] 1.2283696986087564 3 0.602443
4 Univariant [2.5943970420151112, 1.594395887784954] 1.228369698613304 7 0.683610
5 Powell [2.5943950741665596, 1.5943950813799577] 1.2283696986087578 3 1.009171
6 Yogi [2.555939012230438, 1.5550882690033252] 1.230948387588903 100 1.697698
7 RMSprop [-0.00999988470984365, 0.010000139346239431] 1.0404004310290038 100 1.870464
8 Adamax [2.487798183908959, 1.5761850655233682] 1.2427562491630404 100 2.507063
9 Adagrad [2.1728539774681885, 1.82971360617863] 1.6742700801208086 100 2.556201
10 Adam [2.557998679942181, 1.5558893847834132] 1.2307673475752892 100 2.607516
[9]:
from optymus.plots import plot_optim

plot_optim(f_obj=f, x0=initial_point, comparison=comparison, show=True, notebook=True)

Data type cannot be displayed: application/vnd.plotly.v1+json